package com.thyrsus.project.controller.event;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.thyrsus.project.helper.UserHelper;
import com.thyrsus.project.service.event.EventService;

@Controller
@SessionAttributes
public class DeleteEventController {
	
	static Logger LOGGER = Logger.getLogger(DeleteEventController.class);
	
	@Autowired
	private EventService eventService;
	
	@RequestMapping(value = "/event/delete")
    public String doDelete(HttpServletRequest request,HttpServletResponse response) {
		eventService.delete();
		return "redirect:/home";
	}
	
	@RequestMapping("/event/delete/{eventId}")
    public String doDelete(@PathVariable String eventId, Model model, HttpServletRequest request,HttpServletResponse response) {
		eventService.delete(Long.valueOf(eventId).longValue(),UserHelper.getUser(request));
		return "redirect:/home";
	}
}
